<template>
	<view class="order">
		<view class="topsegmented">
			<uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="text"
				activeColor="#ff0000"></uni-segmented-control>
		</view>

		<view class="content" v-if="showEmpty==false">
			<OrderContent :OrderList="OrderList"></OrderContent>

			<view v-if="showaddList">
				<uni-load-more iconType="auto" status="loading" v-show="loadshow==false" />
				<view class="load-txt" v-show="loadshow">没有更多数据了</view>
			</view>
		</view>


		<view class="" v-if="showEmpty">
			<empty text="您没有相关订单!"></empty>
		</view>
		<SorllTop :value="ShowScroll" :ScrollTopTime="200"></SorllTop>
	</view>
</template>

<script>
	import OrderContent from '@/components/OrderContent.vue'
	import empty from '@/components/empty.vue'
	import SorllTop from '@/components/ScrollTop.vue'
	export default {
		components: {
			OrderContent,
			empty,
			SorllTop
		},
		data() {
			return {
				items: ['全部订单', '待付款', '待发货', '已发货', '已完成', '已关闭'],
				current: 0,
				params: {
					pageNum: 1,
					pageSize: 8,
					status: -1,
				},
				OrderList: [],
				showEmpty: false,
				ShowScroll: false,
				showaddList: false,
				loadshow: false,
				total: 0
			}
		},
		onLoad(options) {
			if (options.tab == "false") {
				this.getOrderList()
			} else {
				if (options.current == "0") {
					this.current = 1
					this.params.status = 0;
				} else if (options.current == "1") {
					this.current = 2
					this.params.status = 1;
				} else if (options.current == "2") {
					this.current = 3
					this.params.status = 2;
				} else if (options.current == "3") {
					this.current = 4
					this.params.status = 3;
				} else if (options.current == "4") {
					this.current = 4
					this.params.status = 3;
				}
				this.getOrderList()
			}

		},
		onPageScroll(e) {
			if (e.scrollTop >= 500) {
				this.ShowScroll = true
			} else {
				this.ShowScroll = false
			}
		},
		methods: {
			onClickItem(e) {
				this.loadshow = false
				this.OrderList = []
				if (this.current != e.currentIndex) {
					this.current = e.currentIndex;
				}
				if (this.current == 0) {
					this.OrderList = []
					this.params.status = -1;
					this.getOrderList();
				} else if (this.current == 1) {
					this.OrderList = []
					this.params.status = 0;
					this.getOrderList();
				} else if (this.current == 2) {
					this.OrderList = []
					this.params.status = 1;
					this.getOrderList();
				} else if (this.current == 3) {
					this.OrderList = []
					this.params.status = 2;
					this.getOrderList();
				} else if (this.current == 4) {
					this.OrderList = []
					this.params.status = 3;
					this.getOrderList();
				} else if (this.current == 5) {
					this.OrderList = []
					this.params.status = 4;
					this.getOrderList();
				}

			},
			getOrderList() {
				this.$api.user.portalOrder(this.params).then(res => {
					if (res.code == 200) {
						this.total = res.total
						if (res.total != 0) {
							this.OrderList.push(...res.list)
						}
						if (res.total == 0) {
							this.showEmpty = true
						} else {
							this.showEmpty = false
						}
						if (res.total >= 8) {
							this.showaddList = true
						} else {
							this.loadshow = true
						}
					}
				})
			},
			onReachBottom() {
				if (this.total == this.OrderList.length) {
					this.loadshow = true
				} else {
					setTimeout(() => {
						this.params.pageNum++
						this.getOrderList()
					}, 800)
				}
			},
			// 监听下拉
			onPullDownRefresh(success, fail) {
				this.getOrderList()
				setTimeout(() => {
					uni.stopPullDownRefresh()
				}, 800)
			}
		}
	}
</script>

<style lang="scss">
	.order {
		.topsegmented {
			background-color: white;
		}

		.load-txt {
			text-align: center;
			color: gray;
		}
	}
</style>
